var thiswatch,thisreminder;
var watchstatus=0;
var WatchPageMediator = Objs("view.WatchPageMediator",
	Mediator,
{

	initialize: function( name, viewComponent )
	{ 
	
		WatchPageMediator.$super.initialize.call( this, name, viewComponent );
		thiswatch=this;
		this.vproxy = this.facade.retrieveProxy( ProxyNames.VEHICLE_PROXY );
		this.registerListeners();
		//document.getElementById("remsave").innerHTML="<img src=image/save.png  onclick=thiswatch.save();>";
	},
	registerListeners: function()
	
	{
		var watchPage = this.get();		
	
		watchPage.addEventListener( WatchPage.WATCHLIST, this.onwatch, this );
		watchPage.addEventListener( WatchPage.SAVEWATCHLIST, this.watch, this );
		watchPage.addEventListener( WatchPage.REMOVEWATCHLIST, this.remove, this );
	
	},
	get: function()
	{
		return this.viewComponent;
	},
	onwatch:function()
	{
	
		if ($(jQuery("#checkbox-1")).attr('checked')) {
			$('#hidecont').show('slow');
		}
		else
		{
			$('#hidecont').hide('slow');
		}
	},
	
	remove:function()
	{
	
		this.vproxy.removeWatchlist();
	},
	listNotificationInterests: function()
	{
		return [
				NotificationNames.SAVEREM,
			NotificationNames.REMDET
		];
	},
    handleNotification: function( note )
	{ 
		
		switch ( note.getName() )
		{ 
			case NotificationNames.SAVEREM:
			this.change();
			break;
			case NotificationNames.REMDET:
			this.ReminderPage(note.getBody());
			break;
		
		}
	},
	
	change:function()
	{
	$('#watchlist-modal').modal('hide');
	  
	},
	ReminderPage:function(Remvalues)
	{
	
		thisreminder=Remvalues;
	
		if(Remvalues.vresult==false)
		{
			$('#hidecont').hide('');
			$(jQuery("#checkbox-1")).attr('checked',false);
			watchstatus=0;
			//document.getElementById("remsave").innerHTML="<div  onclick=thiswatch.watch();>Save</div>";
			$("#removerem").hide();
			document.getElementById("datereminder").innerHTML="";

		}
		else
		{
			if(Remvalues.vresult.watch_id)
			{
				$('#hidecont').show('');
				watchstatus=1;
				$(jQuery("#checkbox-1")).attr('checked',true);
				document.getElementById("datereminder").value=Remvalues.vresult.to_date;
				document.getElementById("remnote").value=Remvalues.vresult.remind_note;
					$("#removerem").show();
			}
			else
			{
				$('#hidecont').hide('');

			}
		}		  
	},
	watch:function()
	{
	 if(watchstatus==0)
		this.vproxy.saveWatchlist();
		else
		this.vproxy.updateWatchlist();
	}
	


});

